package com.wiyun.engine.skeleton;


import com.wiyun.engine.nodes.Director;
import com.wiyun.engine.nodes.Label;
import com.wiyun.engine.nodes.Layer;
import com.wiyun.engine.nodes.PageControl;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.nodes.SpriteEx;

import com.wiyun.engine.nodes.PageControl.IPageControlCallback;
import com.wiyun.engine.opengl.Texture2D;
import com.wiyun.engine.types.WYSize;
import com.wiyun.engine.utils.ResolutionIndependent;

public class CardPanelLayer extends Layer implements IPageControlCallback {
	
	public CardPanelLayer()
	{
		CreateCardPanel();
	}
	
	public void CreateCardPanel()
	{
		CardLayer hong_a_card=new CardLayer(R.drawable.hong_a);
		CardLayer fang_a_card=new CardLayer(R.drawable.fang_a);
		CardLayer hei_a_card=new CardLayer(R.drawable.hei_a);
		CardLayer mei_a_card=new CardLayer(R.drawable.mei_a);
		CardLayer mei_a_card1=new CardLayer(R.drawable.test);
		
		PageControl cardPanel=PageControl.make();
		cardPanel.setCallback(this);
		cardPanel.setPageSpacing(DP(80));
		cardPanel.addPage(hong_a_card);
		cardPanel.addPage(fang_a_card);
		cardPanel.addPage(hei_a_card);
		cardPanel.addPage(mei_a_card);
		cardPanel.addPage(mei_a_card1);
		cardPanel.setInitialPage(0);
		this.addChild(cardPanel);
	}
	

	private float DP(float v) {
		return ResolutionIndependent.resolveDp(v);
	}
	
	@Override
	public void onPageChanged(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPageClicked(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onPagePositionChanged(int arg0, int arg1, float arg2) {
		// TODO Auto-generated method stub

	}
	public class CardLayer extends Layer
	{
		public CardLayer(int num)
		{
			CreatePuke(num);
			CreateText(num);
		}
		
		public void CreatePuke(int num)
		{
			WYSize size = Director.getInstance().getWindowSize();
			Texture2D texture = Texture2D.makePNG(num);
			SpriteEx pukeSprite = SpriteEx.make(texture);
			texture.autoRelease();
			pukeSprite.autoRelease();
			//pukeSprite.setAutoFit(false);
			pukeSprite.setPosition(pukeSprite.getWidth()/2,	(pukeSprite.getHeight()*size.height/texture.getHeight())/2);
			pukeSprite.setScaleY(size.height/texture.getHeight());
			this.addChild(pukeSprite);
		}
		
		public void CreateText(int num)
		{
			WYSize size = Director.getInstance().getWindowSize();
			Label pukeLabel = Label.make("asdfasdfasfasdfsafd\nasdfkjasldfkj;sfj");
			pukeLabel.setPosition(size.width/2, size.height/2);
			this.addChild(pukeLabel);
		}
	}
}


